package com.xxxy.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.xxxy.blockhandler.HotspotBlockHandler;
import com.xxxy.blockhandler.MonitorBlockHandler;
import com.xxxy.fallback.Fallback;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/monitor")
public class Controller {

    @GetMapping("/hello")
    @SentinelResource(value = "fallbackResource",blockHandler = "handler",
            blockHandlerClass = MonitorBlockHandler.class)
    public String hello(){
        return "hello world";
    }


    @GetMapping("/hello2")
    @SentinelResource(value = "HelloResource2",blockHandler = "handler",
            blockHandlerClass = MonitorBlockHandler.class)
    public String hello2(){
        return "关联接口";
    }

    @GetMapping("/hello3")
    @SentinelResource(value = "fallback",fallback = "rtFallback",fallbackClass = Fallback.class)
    public String hello3(){
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "超时测试666";
    }
    @GetMapping("/hotspot")
    @SentinelResource(value = "getHotspotResource",blockHandler = "getHotspotBlockHandler",blockHandlerClass = HotspotBlockHandler.class)
    public String getHotspot(@RequestParam(value = "type",required = false) String type,
                             @RequestParam(value = "size",required = false) String size
    ){
        return "进入热点资源";
    }
}
